var fruits = [

    {

        fruitName: '苹果',

        fruitQuantity: 30,

        fruitPrice: 3.8

    },

    {

        fruitName: '西瓜',

        fruitQuantity: 240,

        fruitPrice: 1.8

    },

    {

        fruitName: '芒果',

        fruitQuantity: 60,

        fruitPrice: 7.8

    }

]
// let fruit=fruits.find((item)=>{
//     return item.fruitName==='苹果'
// })
// let fruit = fruits (item => item.fruitName === '苹果')
// let index=fruits.findIndex(item => item.fruitName === '苹果')

let fruit2={

    fruitName: '小芒果',

    fruitQuantity: 60,

    fruitPrice: 7.8

}
let index=fruits.findIndex(item => item.fruitName === fruit2.fruitName)
if(index!=-1){
    fruits[index].fruitQuantity+=fruit2.fruitQuantity
}else{
    fruits.push(fruit2)
}
console.log(fruits);
